package com.ozan.kemal.controller;

import java.sql.Timestamp;
import java.util.Date;

import com.ozan.kemal.db.UserMgrDB;
import com.ozan.kemal.model.User;

public class UserMgr {

	private static UserMgr instance=null;
	private UserMgrDB userDB=UserMgrDB.getInstance();


	public static UserMgr getInstance (){

		if (instance==null){
			instance=new UserMgr();
		}

		return instance;
	}



	public void addNewUser(User u) throws Exception{
		
		Date date =new Date();
		Timestamp timestamp = new Timestamp(date.getTime());
		
		u.setLoginCount(0);
		u.setRegisteredDate(timestamp);
		userDB.addNew(u); 

	}


	public boolean loginUser(User u) throws Exception{
		u =userDB.findUser(u.getUserName(),u.getPassword());
		
		if(u!=null){
			
			Date date =new Date();
			Timestamp timestamp = new Timestamp(date.getTime());
			
			u.setLastLoginDate(timestamp);			
			userDB.setLastLoginDate(u);
			
			return true;
		}
		
		return false;
	
	}
	
	public boolean logoutUser(User u){
		
		
		System.out.println("log out  oldu");
		
		return true;
	
	}


}
